import  {
    device_id,
    iid,
    BASE_URL,
    BASE_IMAGE_URL
} from "./constant.js"
var net = require("./netLoad.js");
var PATH = require("./api-path.js");

//-----------------------数据请求---------------------
function wxLogin(json) {
  let url = BASE_URL + PATH.default.MINE_USER_LOGIN
  return net.fetchApi(url, json, "POST").then(data => data)
}

//---------------------- - 首 页 - ---------------------
function getHomeCateData(){
  console.log(PATH)
  let url = BASE_URL + PATH.default.HOME_GET_BANNERANDCOLUMN
  return net.fetchApi(url, null, "POST").then(data=>{
    for (var i = 0; i < data.appBannerData.length; i++) {
      var item = data.appBannerData[i]
      item.imgUrl = BASE_IMAGE_URL + item.imgUrl
    }
    for (var i = 0; i < data.featuredBanner.length; i++) {
      var item = data.featuredBanner[i]
      item.imgUrl = BASE_IMAGE_URL + item.imgUrl
    }
    return data
  })
}
function getHomeData(json) {
  let url = BASE_URL + PATH.default.HOME_GET_NEWS
  return net.fetchApi(url, json, "POST").then(data => {
    for (var i = 0; i < data.appBannerData.length; i++) {
      var item = data.appBannerData[i]
      item.imgUrl = BASE_IMAGE_URL + item.imgUrl
    }
    for (var i = 0; i < data.featuredBanner.length; i++) {
      var item = data.featuredBanner[i]
      item.imgUrl = BASE_IMAGE_URL + item.imgUrl
    }
    return data
  })
}

export {
  getHomeCateData, 
  getHomeData,
  wxLogin
} 
